package testcase.doctor;

import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;

import org.json.JSONException;
import org.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.xml.sax.SAXException;

import api.doctor.UploadMessage;
import common.Host;
import common.TestData;

/**
 * 帮忙医医生端上传消息接口UploadMessage测试用例
 * @author gaowen
 *
 */
public class TestUploadMessage
{
	/**
	 * 帮忙医医生端上传消息接口UploadMessage测试环境数据驱动
	 * @return 测试数据
	 * @throws ParserConfigurationException
	 * @throws SAXException
	 * @throws IOException
	 */
	@DataProvider(name="Test")
	public static String[][] testMessageDataProvider() throws ParserConfigurationException, SAXException, IOException
	{
		Host.setup("Test");
		TestData testData=new TestData("doctor/TestUploadMessage.xml");
		return testData.getParam();
	}
	
	/**
	 * 帮忙医医生端上传消息接口UploadMessage测试环境测试用例
	 * @param caseName 用例名
	 * @param Message 消息内容
	 * @param FromUserID 发送者ID
	 * @param FromUserName 发送者姓名
	 * @param FromUserFace 发送者头像
	 * @param ToUserID 接受者ID
	 * @param MessageTime 消息时间
	 * @param CloudMessageID 云消息ID
	 * @param SubjectID 会话ID
	 * @param MessageType 消息类型
	 * @param isRead 是否已读
	 * @param token 调接口需要的token
	 * @throws JSONException
	 * @throws IOException
	 */
	@Test(dataProvider="Test",groups="Test")
	public void testMessageTestCase(String caseName,String Message,String FromUserID,String FromUserName,String FromUserFace,String ToUserID,String MessageTime,String CloudMessageID,String SubjectID,String MessageType,String isRead,String token) throws JSONException, IOException
	{
		String result=UploadMessage.post(Message, FromUserID, FromUserName, FromUserFace, ToUserID, MessageTime, CloudMessageID, SubjectID, MessageType, isRead, token);
		
		JSONObject jsonResult;
		if(result==null||result.isEmpty())
		{
			jsonResult=null;
		}
		else
		{
			jsonResult=new JSONObject(result);
		}
		
		switch (caseName)
		{
			case "Success":
				Assert.assertTrue(jsonResult.getJSONArray("Data").getJSONObject(0).getBoolean("Success"));
				break;
			case "MessageNull":
				Assert.assertTrue(jsonResult.getJSONArray("Data").getJSONObject(0).getBoolean("Success"));
				break;
			case "FromUserIDWrong":
				Assert.assertTrue(jsonResult.getJSONArray("Data").getJSONObject(0).getBoolean("Success"));
				break;
			case "FromUserIDNull":
				Assert.assertTrue(jsonResult.getJSONArray("Data").getJSONObject(0).getBoolean("Success"));
				break;
			case "ToUserIDWrong":
				Assert.assertTrue(jsonResult.getJSONArray("Data").getJSONObject(0).getBoolean("Success"));
				break;
			case "ToUserIDNull":
				Assert.assertTrue(jsonResult.getJSONArray("Data").getJSONObject(0).getBoolean("Success"));
				break;
			case "MessageTimeWrong":
				Assert.assertFalse(jsonResult.getJSONArray("Data").getJSONObject(0).getBoolean("Success"));
				break;
			case "MessageTimeNull":
				Assert.assertFalse(jsonResult.getJSONArray("Data").getJSONObject(0).getBoolean("Success"));
				break;
			case "CloudMessageIDWrong":
				Assert.assertTrue(jsonResult.getJSONArray("Data").getJSONObject(0).getBoolean("Success"));
				break;
			case "CloudMessageIDNull":
				Assert.assertTrue(jsonResult.getJSONArray("Data").getJSONObject(0).getBoolean("Success"));
				break;
			case "SubjectIDWrong":
				Assert.assertTrue(jsonResult.getJSONArray("Data").getJSONObject(0).getBoolean("Success"));
				break;
			case "SubjectIDNull":
				Assert.assertTrue(jsonResult.getJSONArray("Data").getJSONObject(0).getBoolean("Success"));
				break;
			case "MessageTypeWrong":
				Assert.assertTrue(jsonResult.getJSONArray("Data").getJSONObject(0).getBoolean("Success"));
				break;
			case "MessageTypeNull":
				Assert.assertTrue(jsonResult.getJSONArray("Data").getJSONObject(0).getBoolean("Success"));
				break;
			case "IsReadWrong":
				Assert.assertTrue(jsonResult.getJSONArray("Data").getJSONObject(0).getBoolean("Success"));
				break;
			case "IsReadNull":
				Assert.assertTrue(jsonResult.getJSONArray("Data").getJSONObject(0).getBoolean("Success"));
				break;
			case "TokenWrong":
				Assert.assertTrue(jsonResult.getJSONArray("Data").getJSONObject(0).getBoolean("Success"));
				break;
			case "TokenNull":
				Assert.assertTrue(jsonResult.getJSONArray("Data").getJSONObject(0).getBoolean("Success"));
				break;
			default:
				break;
		}
	}
}
